package homework.Thirty;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class EventTest2 {
    public static void main(String[] args) {
        Frame frame=new Frame("测试窗口");
        frame.setSize(new Dimension(640,640));
        frame.setLayout(new BorderLayout());
        Panel panel=new Panel();
        MyButton2 myButton2=new MyButton2("Left Button");
        panel.add(myButton2);
        frame.add(panel);
        frame.setVisible(true);

    }
}

class MyButton2 extends Button implements ActionListener{
    public MyButton2(String b){
        super(b);
        addActionListener(this);
    }

    @Override
    public void actionPerformed(ActionEvent e){
        String arg=e.getActionCommand();
        if ("Left Button".equals(arg)){
            System.out.println("Press Left Button");
        }
    }
}
